<?php
/**
 * Class 
 *
 * @access  public
 * @author  DucLH
 * @copyright 
 * @version $Id:1.0
 * @update  2010/06/30
 * @create  2010/06/01
 */
namespace Libs\Kvs\TokyoTyrant;

class TokyoTyrantCommon
{
	private $objTt;	
	public function __construct(){
    	//$this->container = $container;
		//$this->oTokyoTyryrant = new \TokyoTyrant(TOKYO_TYRANT_HOST, TOKYO_TYRANT_PORT);
		//$this->objTt = new \TokyoTyrantTable(TOKYO_TYRANT_HOST, TOKYO_TYRANT_PORT);
		$this->objTt = new \TokyoTyrantTable();
		
		$this->objTt->connectUri("tcp://".TOKYO_TYRANT_HOST.":".TOKYO_TYRANT_PORT."/");
		//$this->oTokyoTyryrant = new \TokyoTyrant("localhost", 1978);
  	}
	/**
     *
     * DucLH
     * 
     * @access  public
     * @param           
     * @return  
     */
	function genUid(){
		$this->objTt->genUid();
	}
	/**
     *
     * DucLH
     *
     * @access  public
     * @param   String $sKey        
     * @return  
     */
	function put($sKey, $aryData){
		$index = $this->objTt->put($sKey, $aryData);
	}
	/**
     *
     * DucLH
     *
     * @access  public
     * @param   String $sKey        
     * @return  Array 
     */
     function get($sKey){
		return  $this->objTt->get($sKey);
	}
	 
	 /**
	 *
	 * @author TrieuPM (trieupm@vitalify.asia)
	 * @access public
	 * @param  String $sKey
	 * @return Array
	 */
	function out($skey){
	    $this->objTt->out($skey);
	}
	
	/**
     *
     * DucLH
     *
     * @access  public
     * @param   String $sKey        
     * @return  Array 
     */
     function getIterator(){
		return  $this->objTt->getIterator();
	}
	 /**
     *
     * DucLH
     *
     * @access  public
     * @param   String $sKey        
     * @return  Array 
     */
     function getQuery($key, $value){
		
		/* Get query object */
		$query = $this->objTt->getQuery();
		
		/* Add condition to query */
		$query->addCond($key, \TokyoTyrant::RDBQC_STREQ, $value);
		
		/* Get matching rows */
		$result = $query->search();
		/* Remove matching records */
		$query->out();
		
		return $result;
		/* Count the results */
		//var_dump($query->count());
	} 
}